package DBfun;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DBconnection {

	static final String url = "jdbc:odbc:Driver={Microsoft Access Driver " +
            "(*.mdb, *.accdb)};DBQ=D://workspace//ImitateQQ//account.accdb";
	static final String drive = "sun.jdbc.odbc.JdbcOdbcDriver";

	
	static
	{
		try {
			Class.forName(drive);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

	}

	public static  Connection getConnection()
	{
		try {
			return DriverManager.getConnection(url,"root","111111");
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	public static void closeConnection(ResultSet rs,Statement s,Connection con)
	{
	    
	    try {
	    	if(rs!=null)rs.close();
	    	if(s!=null)s.close();
	    	if(con!=null)con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	
	public static void closeConnection(Statement s,Connection con)
	{
	    
	    closeConnection(null,s,con);
		
	}
	
	

}
